Uec3.ReturnedEditWin = Ext.extend(Ext.UecWindow,{
	
	fieldNames :['areaId','province','city','district','street','postCode','receiverName','phone','mobile'],
	
	deleteItemIds : [],
	
	constructor : function(config){
		
		var module = this;
		
		this.params = config.params||{},
		
		this.transportTypeCombo = Uec3.App.dictionary.getCombo("transportType",{fieldLabel:'运输类型',hiddenName:'transportType',grid:[4,3,4,3],showWhole:true});
		
		this.partSourceCombo = Uec3.App.dictionary.getCombo("part_source",{hiddenName:'source'});
		
		this.partnerCombo = getPartnerLookup(1,{grid:[2,3,2,3],app:this.params.app});
		
		this.partnerAddCombo = getPartnerAddLookup(this.partnerCombo,{emptyText:'选择退货地址...',grid:[2,4,6,4],app:this.params.app});		
			
		this.toolBar = new Ext.Toolbar({
			items:[
				{text : '新增明细',iconCls : 'icon-add',itemId:'addItemButton',handler:this.showAddForm,scope:this}
		   ]
		});
		/**
		 * 主表区域
		 */
		this.northPanel = new Ext.FormPanel({
			frame : true,
			region : 'north',
			width:'100%',
			layout:'uec3grid',
			layoutConfig:{
				hGrid:[6,32,6,12,6,18,5,15],
				vGrid:[25,15,30,30]					  	
			},
			height:110,
			items:[
				{
					xtype:'label',
					text:'采购退货单',
				 	style : {font : 'bold 18px arial, serif',textAlign : 'center'},
				 	grid : [3, 1, 5, 1]
				},{
					xtype : 'label',
					text : '单据号:',
					style:{fontSize:'13px',marginLeft:'2px'},
					grid : [7,1,7,1]
				},{
					xtype : 'textfield',																				  
					name : 'codeOfBuyer',							 
					readOnly :true,
					style:{background:'#dddddd', width:'130px'},					
				    grid:[8,1,8,1]
				},{
					html:'<hr color="#34A4E0" />',
					grid:[1,2,8,2]
				},{
	 	            xtype:'label',
	 	            text:'供货单位:',
	 	            grid:[1,3,1,3]
			 	},this.partnerCombo,
			 	{
			 		xtype:'label',
			 	    text:'运输方式:',
					style:{marginLeft:'2px'},
					grid : [3,3,3,3]
			 	},this.transportTypeCombo,
			 	{
			 		xtype:'label',
			 	    text:'退货日期:',
			 	    grid:[5,3,5,3]
			 	},{
			 		xtype:'datefield',				 	
			 		name:'gmtAccept',
				    format:'Y-m-d H:i:s',
				    grid:[6,3,6,3]
			 	},{
			 		xtype:'label',
			 	    text:'备注:',
			 	    grid:[7,3,7,3]
			 	},{
			 		xtype:'textarea',
			 		autoScroll:true,
			 	    name:'memo'	,
			 	    grid:[8,3,8,4]
			 	},{
			 		xtype:'label',
			        text:'退货地址:',
			        grid:[1,4,1,4]
			 	},this.partnerAddCombo,
			 	{xtype:'hidden',name : 'id'},
			 	{xtype:'hidden',name : 'sellerId'},
			 	{xtype:'hidden',name : 'status'},
			 	{xtype:'hidden',name : 'areaId'},
			 	{xtype:'hidden',name : 'province'},
			 	{xtype:'hidden',name : 'city'},
			 	{xtype:'hidden',name : 'district'},
			 	{xtype:'hidden',name : 'street'},
			 	{xtype:'hidden',name : 'postCode'},
			 	{xtype:'hidden',name : 'receiverName'},
			 	{xtype:'hidden',name : 'phone'},
			 	{xtype:'hidden',name : 'mobile'}		
			]			
		});
		
		/**
		 * 明细表区域
		 */
		var gridColumn = new Ext.grid.ColumnModel({
			columns:[
				new Ext.grid.RowNumberer(),
				{
				 header:'操作',
				 xtype:'anchorcolumn',
				 width : 100,
				 dataIndex : 'act',
				 items:[
				   {
					text:"删除",
					scope:this,
					//permissionId:25,
					handler:this.deleteReturnedItem
				   }
				 ]
				},
				{header:'零件编码',dataIndex:'code'},
			    {header:'零件名称',dataIndex:'name'},
			    {header:'来源',dataIndex:'source',renderer:Ext.util.Format.comboRenderer(this.partSourceCombo)},
			    {header:'车型',dataIndex:'carModel'},
			    {header:'单位',dataIndex:'measurementUnit'},
			    {header:'退货数量',dataIndex:'quantity',
			        editor:new Ext.form.NumberField({
							 allowBlank: false,
			 				 allowNegative: false
					  }),
					  tooltip :'单击单元格,修改退货数量'
			    },                         
			    {header:'进价',dataIndex:'cost'},
			    {header:'退货金额',dataIndex:'costAmount',renderer:function(value, metaData, record){
			    	 return (record.data.quantity*record.data.cost);
			    }},
			    {header:'媒体价',dataIndex:'retailPrice'},                   
			    {header:'品牌',dataIndex:'brand'},
			    {header:'产地',dataIndex:'origin'},
			    {header:'仓库',dataIndex:'storeName'},
			    {header:'仓位',dataIndex:'shelf'}
			],
			defaults: {
          		//sortable: true,
          		menuDisabled: true,
          		width:120
       		}
		});
		
		var returnedItems_grid_store = new Ext.data.JsonStore({
			root:'',
            pruneModifiedRecords:true,
            fields:[  
   		        {name:'id'},
                {name:'returnedId'},  // -- 退货单ID
                {name:'partId'},
                {name:'sourceInventoryId'},// 来源零件库存ID(指定了从哪个库存上退货)
                {name:'code'},
                {name:'name'},
                {name:'source'},
                {name:'measurementUnit'},            
                {name:'quantity'},  // -- 退货数量
                {name:'onHand'},
                {name:'cost'},      // -- 进价
                {name:'retailPrice'},  // -- 售价               
                {name:'brand'},
                {name:'origin'},
                {name:'storeId'},
                {name:'storeName'},
                {name:'shelf'},		                 
                {name:'nameEn'},
                {name:'pyCode'},
                {name:'partCategoryId'},
                {name:'level1Name'},
                {name:'level2Name'},
                {name:'level1Id'},
                {name:'costAmount'}, // -- 退货金额
                {name:'carModel'}
            ]
		});
		
		this.centerPanel = new Ext.grid.EditorGridPanel({
			frame : false,
			columnLines :true,
			region:'center',
			//height:152,                   
			enableHdMenu : false,
			itemId:'returned_items_form_grid',
			stripeRows: true,
			store:returnedItems_grid_store,
			//autoWidth : true,	   	   
			viewConfig:{scrollOffset:15},
			clicksToEdit:1,
			autoScroll: true,
			colModel:gridColumn,
			tbar : this.toolBar,
			selModel:new Ext.grid.RowSelectionModel({moveEditorOnEnter:true,singleSelect :true})			
		});
		
		/**
		 * 按钮区域
		 */
		this.southPanel = new Ext.FormPanel({
			labelAlign:'left',
			region :'south',
			height:65,
			frame:true,
			items:[
				{
					layout:'uec3grid',
					layoutConfig:{
						hGrid:[6,7,5,7,6,7,5,7,6,7,5,7,6,7,5,7],
						vGrid:[100]					  	
					},
					height:26,
					defaultType:'textfield',
					items:[
						{xtype:'label',text:'订单状态:',grid : [1, 1, 1, 1]},
						{name:'statusName',readOnly:true,style:{background:'#dddddd'},grid : [2,1,2,1]},
						{xtype:'label',text:'创建人:',grid : [3, 1, 3, 1]},
						{name:'creatorName',readOnly:true,style:{background:'#dddddd'},grid : [4,1,4,1]},
						{xtype:'label',text:'创建时间:',grid : [5, 1, 5, 1]},
						{name:'gmtCreate',readOnly:true,style:{background:'#dddddd'},grid : [6,1,6,1]},
						{xtype:'label',text:'提交人:',grid : [7, 1, 7, 1]},
						{name:'submitterName',readOnly:true,style:{background:'#dddddd'},grid : [8,1,8,1]},
						{xtype:'label',text:'提交时间:',grid : [9, 1, 9, 1]},
						{name:'gmtSubmit',readOnly:true,style:{background:'#dddddd'},grid : [10,1,10,1]},
						{xtype:'label',text:'审核人:',grid : [11, 1, 11, 1]},
						{name:'depositerName',readOnly:true,style:{background:'#dddddd'},grid : [12,1,12,1]},
						{xtype:'label',text:'审核时间:',grid : [13, 1, 13, 1]},
						{name:'gmtDepositer',readOnly:true,style:{background:'#dddddd'},grid : [14,1,14,1]},
						{xtype:'label',text:'总金额:',grid : [15, 1, 15, 1]},
						{name:'amount',readOnly:true,style:{background:'#dddddd'},grid : [16,1,16,1]}
					]				
				}
			]		
		});
		
		config = Ext.apply(config||{},{items:[this.northPanel,this.centerPanel,this.southPanel]});
		
		Uec3.ReturnedEditWin.superclass.constructor.call(this,config);
	},
	
	 //private
	initComponent:function(){
		Uec3.ReturnedEditWin.superclass.initComponent.call(this);
	},
	
	
	operation : function(btn){
		eval("this."+btn.func+"(btn)");
	},
	
	showAddForm : function(){
		var module = this;
		var partnerId = this.partnerCombo.getValue();
		if(Ext.isEmpty(partnerId)){
			Ext.MessageBox.alert("提示","请先填写供货商信息");
		}else{
			redirectUrl("returnedItemAdd",{partnerComb : this.partnerCombo,returnedItemRecords : this.centerPanel.getStore().getRange(),
						fn:function(record){
						    var returned_items_form_store = module.centerPanel.getStore();					   		
							if(record.get('isAdd')){
								var index = returned_items_form_store.findExact("sourceInventoryId",record.get('sourceInventoryId'));
								if(index != -1){
						    		var oldRecord = returned_items_form_store.getAt(index);
						    		oldRecord.set('quantity',record.get('quantity'));
			   						returned_items_form_store.commitChanges(); 
						    	}else{
									returned_items_form_store.add(record);
								}								
							}else{
								returned_items_form_store.remove(record);
							}
									
						}
			});
		}		
	},
	
	/**
	 * 根据所选地址自动填充供货商地址、邮编、联系人等信息
	 */
	fillPartnerAddressInfo : function(record){
		Ext.each(this.fieldNames,function(fieldName,index,array){
		 	if(record.data){
		 		this.northPanel.getForm().findField(fieldName).setValue(record.data[fieldName]);
		 	}else{
		 		this.northPanel.getForm().findField(fieldName).setValue(record[fieldName]);
		 	}			 	 
		},this);
	},
	
	/**
	 *  清空供货商地址、邮编、联系人等信息
	 */
	clearPartnerAddressInfo : function(){		    
		Ext.each(this.fieldNames,function(fieldName,index,array){			 	 
			this.northPanel.getForm().findField(fieldName).reset();
		},this);	 
	},
	/**
	 * 删除明细
	 * @param {} grid
	 * @param {} rowIndex
	 * @param {} colIndex
	 * @param {} item
	 * @param {} e
	 */
	deleteReturnedItem:function(grid, rowIndex, colIndex, item, e){
		var returned_items_form_store = grid.getStore();
		var record = returned_items_form_store.getAt(rowIndex);
		var id = record.data.id;			 
		returned_items_form_store.removeAt(rowIndex);
		if(id){
			this.deleteItemIds.push(id);
		}
		grid.getView().refresh();
	},
	//private 
	initEvents : function(){
		var module = this;
		Uec3.ReturnedEditWin.superclass.initEvents.call(this);
		this.transportTypeCombo.getStore().load();
		this.partSourceCombo.getStore().load();
		this.on('show',this.winAfterShow,this);	
		this.partnerCombo.on('select',module.selectPartnerComb,module);
		this.partnerCombo.on('lookupChange',module.lookupChangePartnerComb,module);
		this.partnerCombo.on('lookupClear',module.resetWholeRecord,module);
		this.partnerAddCombo.on('lookupChange',module.fillPartnerAddressInfo,module);
		this.partnerAddCombo.on('lookupClear',module.clearPartnerAddressInfo,module);
	},
	
	selectPartnerComb : function(lookup,record,index){
		if(lookup.getValue() && (lookup.getValue() + '').trim() != '' && lookup.getValue() != record.data.id ) {
			Ext.MessageBox.confirm("提示", '确定更改供货单位?',function(btnId){
				if(btnId == "no"){
					return;
				}else{
					//lookup.initializeValue({'name':record.data.name,'pyCode':record.data.pyCode,'id':record.data.id});
					lookup.setValue(record.data[lookup.valueField], record.data[lookup.lookupField]);					
					this.setParamForField(record);
				}
			},this);
		}else if(!lookup.getValue()){
			lookup.setValue(record.data[lookup.valueField], record.data[lookup.lookupField]);
			this.setParamForField(record);
		}
	},
	
	lookupChangePartnerComb : function(record, creator, oldValue, win){
		if(oldValue && (oldValue + '').trim() != '' && record.data.id != oldValue ){
			Ext.MessageBox.confirm("提示", '确定更改供货单位?',function(btnId){
				if(btnId == "no"){
					return;
				}else{					
					creator.setLookupValue(record.data, win);
					this.setParamForField(record);
				}
			},this);
		}else if(!oldValue){
			creator.setLookupValue(record.data, win);
			this.setParamForField(record);
		}
	},
	
	resetWholeRecord : function(){
		Ext.MessageBox.confirm("提示","确定删除该供货单位?",function(btnId){
			if(btnId == 'yes'){
				this.clearAllTabel();
			}				
		},this);	  
	},
	
	clearAllTabel : function(){
		var myMask = new Ext.LoadMask(this.el,{msg : "处理中,请稍后...."});
    	myMask.show();
    	this.northPanel.getForm().reset();
    	this.partnerCombo.clearValue();
    	this.partnerAddCombo.clearValue();
    	this.clearPartnerAddressInfo();
    	this.centerPanel.getStore().removeAll();
		this.southPanel.getForm().reset();
    	myMask.hide();
	},
	
	setParamForField : function(record){
		this.northPanel.getForm().findField("sellerId").setValue(record.data.companyId);
 	    this.clearPartnerAddressInfo();
	},
	
	initButtons : function(){
		var myMask = new Ext.LoadMask(this.el,{msg : "按钮加载中,请稍候...."});
        myMask.show();
        Ext.Ajax.request({
			url:Uec3.App.Constants.homeUrl+"/returned/toReturned!getInitialButtons.do",
			callback :function(options,success,response){
			     myMask.hide();    
			},
			success: function(response,options){
				var resp =Ext.decode(response.responseText);
				var buttons = resp.buttons;					 	
				//显示相应按钮条
				this.addButtonPanel(buttons,this.southPanel);
			},
			failure: function(response,options){
				Ext.MessageBox.alert("提示","初始化按钮出错!");
			},
			scope: this
		});
	},
	
	initReturnedAndItemById : function(id){
		var myMask = new Ext.LoadMask(this.el,{msg : "采购退货单加载中,请稍候...."});
        myMask.show();
        Ext.Ajax.request({
			url:Uec3.App.Constants.homeUrl+"/returned/toReturned!toReturnedItemEdit.do",
			params: {queryParam:id},
			callback :function(options,success,response){
				myMask.hide();   
			},
			success: function(response,options){
				var resp =Ext.decode(response.responseText);
				if(resp.success){
					this.fillMainContent(resp);
					//改变窗口的title
					changeWindowUecId(resp.main.codeOfBuyer,this.params.uecId);
				}else{
					Ext.MessageBox.alert("提示",resp.msg);
				}
			},
			failure: function(response,options){
				Ext.MessageBox.alert("提示","加载采购退库单据错误!");
			},
			scope: this
			});
	},
	/**
	 * 显示主表,明细
	 * @param {} responseObj
	 */
	fillMainContent : function(responseObj){
		// 主表
		var returned_main_data = responseObj.main;
		// 明细表
		var returned_details_data = responseObj.details;
		// 返回信息
		var msg = responseObj.msg;
		// 按钮
		var buttons = responseObj.buttons.buttons;
		// 是否单据所有者
		var isOwner = responseObj.buttons.isOwner;
		// 主表显示
		this.northPanel.getForm().setValues(returned_main_data);	
		this.partnerCombo.initializeValue({'name':returned_main_data.partnerName,'pyCode':returned_main_data.pyCode,'id':returned_main_data.partnerIdByBuyer});
		this.partnerAddCombo.initializeValue({'areaId':returned_main_data.areaId,'address':returned_main_data.province+returned_main_data.city+returned_main_data.district+returned_main_data.street+","+returned_main_data.receiverName+","+returned_main_data.phone+","+returned_main_data.mobile});	  
		//状态面板
		this.southPanel.getForm().setValues(returned_main_data);
		// 明细表显示
		this.centerPanel.getStore().loadData(returned_details_data);
		// 显示相应按钮条
		this.addButtonPanel(buttons,this.southPanel);		  	  
		//判断是否所有者打开当前单据,页面不同展示效果
		this.rendererSpecificColumnByConditon(isOwner);
		// 显示提示信息
		if(msg.confirm){
			this.toPayInvoice(msg.confirm,responseObj.payableId,responseObj.customerId);		  	   		
		}else if(msg.alert){
			Ext.MessageBox.alert("提示",msg.alert);
		}
	},
	
	
	getAllReturnedItems : function(){		  
		   var totalRecords = this.centerPanel.getStore().getRange();
		   var totalDatas =[];
		   for(var i=0;i<totalRecords.length;i++){
		       totalDatas.push(totalRecords[i].data);
		   }
		   //var returned_mainInfo = returned_items_form.getComponent("returned_mainInfo");
		   this.northPanel.enable();
		   var mainData = this.northPanel.getForm().getValues();
		   delete mainData.address;	
		   this.rendererSpecificColumnByConditon(true);
		   if(Ext.isEmpty(mainData.partnerIdByBuyer,false)){
		   	  Ext.MessageBox.alert('提示','请选择供货商!');
		      return;
		   }
		   if(Ext.isEmpty(totalDatas)){
		      Ext.MessageBox.alert('提示','未有退库明细!');
		      return;
		   }
		   var returned={main:mainData,details:totalDatas,deleteItemIds:this.deleteItemIds};
		   var returnedObj=Ext.encode(returned);
		   return returnedObj;
	},	
	
	setReadOnlySpecifyField : function(fieldList){
		 Ext.each(fieldList,function(item,index,array){
	         var field = this.northPanel.getForm().findField(item);
	         field.setReadOnly(true);	        
	         field.getEl().setStyle('background','#dddddd');
	     },this);
	},
	
	cancelReadOnlySpecifyField : function(fieldList){
		 Ext.each(fieldList,function(item,index,array){
	         var field = this.northPanel.getForm().findField(item);
	         field.setReadOnly(false);	        
	         field.getEl().setStyle('background','');
	     },this);
	},
	
	rendererSpecificColumnByConditon: function(isOwner){
		 var status =  this.northPanel.getForm().findField("status").getValue();	
  		 var gridMask =new Ext.LoadMaskJUPIT(this.centerPanel.getView().mainBody);	
  		 var fieldList =['partnerIdByBuyer','transportType','gmtAccept','memo','address'];
  		 if(isOwner){
  		    if(status == 1){
  		    	this.setReadOnlySpecifyField(fieldList);
  		    	gridMask.hide();
  		    	this.toolBar.disable();
  		    }else if(status == 2){
  		    	this.setReadOnlySpecifyField(fieldList);
  		    	gridMask.show();
  		    	this.toolBar.disable();
  		    }else{
  		    	this.cancelReadOnlySpecifyField(fieldList);
  		    	gridMask.hide();
  		    	this.toolBar.enable();
  		    }
  		 }else{
  		 	 this.setReadOnlySpecifyField(fieldList);
  		     gridMask.show();
  		     this.toolBar.disable();
  		 }		  		
	},
	
	/**
	 * 保存草稿
	 */
	backupDraft:function(btn){
		this.backupReturnedAndItems(btn,'确定保存草稿?','草稿保存中,请稍后.......');
	},
	/**
	 * 提交仓库
	 */
	backupSubmit:function(btn){
		this.backupReturnedAndItems(btn,'确定保存单据为待仓库审核状态?','待审核单据保存中,请稍后.......');
	},
	  
	/**
	 * 直接退库
	 */
	deposit:function(btn){
		this.backupReturnedAndItems(btn,"确定退库?","正在退库中,请稍后.....");
	},
	
	/**
	 * 重置表单
	 */
	reset:function(){
		Ext.MessageBox.confirm("提示","确定清空表单?",function(btnId){
			if(btnId == 'yes'){
				this.clearAllTabel();
			}				
		},this);
	},
	
	/**
	 * 跳转浏览退库单页面
	 */
	returnedBrowser:function(btn){
		redirectUrl("returned_browser");
	},
	/**
	 * 跳转新增采购退库页面
	 */
	newCreateReturned:function(btn){
		redirectUrl("returned_edit");
	},
	/**
	 * 打印单据
	 */
	printReturned:function(){
		alert("to be continued.....");
	},
	/**
	 * 退出
	 */
	exit:function(btn){
		Ext.MessageBox.confirm("提示","确定退出?",function(btnId){
			if(btnId == 'yes'){
				this.close();
			}				
		},this);	
	},
	/**
	 * 接手单据
	 */
	acceptReturned:function(btn){
		this.acceptOrReleaseReturned(btn,'确定接手单据?','正在接手单据,请稍后......');
	},
	/**
	 * 释放单据
	 */
	releaseReturned:function(btn){
		this.acceptOrReleaseReturned(btn,"确定释放单据?","正在释放单据,请稍后.....");
	},

	 /**
	  *根据Id删除退库单 
	  */ 
	deleteDraft:function(btn){
		var returnedId = this.northPanel.getForm().findField("id").getValue();
		if(!Ext.isEmpty(returnedId)){
			Ext.MessageBox.confirm("提示",msg,function(btnId){
				if(btnId=='yes'){
					var myMask = new Ext.LoadMask(this.el,{msg : "退库单草稿删除中,请稍后...."});
					myMask.show();
					Ext.Ajax.request({
						url:btn.url,
						params :{queryParam:returnedId},
						method :"post",
						callback :function(options,success,response){
							myMask.hide();
						},
						success:function(response,options){
							var resp = Ext.decode(response.responseText);
							if(resp.success){
								this.close();
								redirectUrl("returned_browser");            		
							}
							Ext.MessageBox.alert("提示",resp.msg);            				
						},
						failure:function(response,options){
							Ext.MessageBox.alert("提示","发生异常，请稍候处理!");    
						},
						scope:this
					});
				}
			},this);
		}   
	},
	/**
	 * 处于待仓库点数状态下的退库单退回草稿
	 */
	backToDraft:function(btn){
		var returnedId = this.northPanel.getForm().findField("id").getValue();
		if(!Ext.isEmpty(returnedId)){
			Ext.MessageBox.confirm("提示",msg,function(btnId){
				if(btnId=='yes'){
					var myMask = new Ext.LoadMask(this.el,{msg : "退库单退回草稿中,请稍后...."});
					myMask.show();
					Ext.Ajax.request({
						url:btn.url,
						params :{queryParam:returnedId},
						method :"post",
					callback :function(options,success,response){
						myMask.hide();
					},
					success:function(response,options){					        
						var resp = Ext.decode(response.responseText);
						Ext.MessageBox.alert("提示",resp.msg);
						if(resp.success){             		   
							this.fillMainContent(resp);
						}				    					   
					},
					failure:function(response,options){
						Ext.MessageBox.alert("提示","网络连接异常，请稍候处理!");    
					},
					scope:this
					});	 		
				}
			},this);
		}
	},
	
	backupReturnedAndItems:function(btn,msg,wait){
		var returned = this.getAllReturnedItems();	
		if(!Ext.isEmpty(returned)){
			Ext.MessageBox.confirm("提示",msg,function(btnId){
				if(btnId=="yes"){
					var myMask = new Ext.LoadMask(this.el,{msg:wait});
					myMask.show();
					Ext.Ajax.request({		  	         
						url:btn.url,
						method :"post",					   
						params:{queryParam:returned},
						timeout:180000,
						callback :function(options,success,response){
							myMask.hide();
						},
						success:function(response,options){
							var resp = Ext.decode(response.responseText);
							if(resp.success){				        
								this.fillMainContent(resp);
								changeWindowUecId(resp.main.codeOfBuyer,"returned_edit","returned_edit_"+resp.main.id);
							}else{
								Ext.MessageBox.alert("提示",resp.msg);
							} 
						},
						failure:function(response,options){
							Ext.Msg.alert('提示','网络连接异常，请稍候处理!');						
						},
						scope:this
					});
				}
			},this);
		}	      	  	   
	},
	
	acceptOrReleaseReturned:function(){
		var returnedId = this.northPanel.getForm().findField("id").getValue();
		if(!Ext.isEmpty(returnedId)){
			Ext.MessageBox.confirm("提示",msg,function(btnId){
				if(btnId=='yes'){
					var myMask = new Ext.LoadMask(this.el,{msg : wait});
					myMask.show();
					Ext.Ajax.request({
						url:btn.url,
						params :{queryParam:returnedId},
						method :"post",
						timeout:180000,
						callback :function(options,success,response){
							myMask.hide();
						},
						success:function(response,options){
							var resp = Ext.decode(response.responseText);
							if(resp.success){
								var buttons = resp.buttons;
								var isOwner = resp.isOwner;			    				
								// 显示相应按钮条
								this.addButtonPanel(buttons,this.southPanel);
								this.rendererSpecificColumnByConditon(isOwner);	                    
							}else{
								Ext.MessageBox.alert("提示",resp.msg);
							}
						},
						failure:function(response,options){
							Ext.MessageBox.alert("提示","网络连接异常，请稍候处理!"); 
						},
						scope:this
					});
				}
			},this);
		}	  	 
	},
	
	toPayInvoice : function(msg,payableId,customerId){
		Ext.MessageBox.confirm("提示",msg,function(btnId){
			if(btnId == 'yes'){		  	       
				//跳转付款单页面		  	  	  
				Uec3.App.getDesktop().launchWindowByParam("payInvoice_operation",{winId:'returned'+payableId,payableIds:payableId,customerId:customerId});
			}
		},this);
	},
	
	winAfterShow : function(){
		if(this.params && this.params.id){
        	this.initReturnedAndItemById(this.params.id);
		}else{
        	this.initButtons();
        }
	}
	
});

Uec3.ReturnedEditWindow = Ext.extend(Ext.app.Module,{
	id: 'returned_edit',
	
	createWindow : function(params){
		
		var windowId='returned_edit';
		if(params){	  	
			windowId += Ext.isEmpty(params.winId)?"":"_"+params.winId;
		}
		params.uecId=windowId;
		params.app = this.app;
		var desktop = this.app.getDesktop();
		// var win = desktop.getWindow(windowId);
		var win = desktop.getWindowByUecId(windowId);
		if(!win){
			win = desktop.createWindow({
				//id: windowId,
				uecId:windowId,
				title: '采购退库',
				params : params,
				width: 1000,
				height: 500,
				minWidth:1000,
				minHeight:500,
				iconCls: 'acc-icon',
				shim: false,
				animCollapse: false,
				constrainHeader: true,
				maximizable: true,
				taskbuttonTooltip: "采购退库",
				layout: "border"         
			},Uec3.ReturnedEditWin);
		}else{
			win.params = params;
		}		
		win.show();
	} 
});